import moment from "moment"
// 日期
export const runTime = ()=>{
    let timeold =
        new Date().getTime() -
        new Date(1627747200000).getTime();
    let  msPerDay = 24 * 60 * 60 * 1000;
    let  daysold = Math.floor(timeold / msPerDay);
    let daytime = new Date();
    day.value = daysold;
    hours.value = daytime.getHours();
    minute.value = daytime.getMinutes();
    second.value = daytime.getSeconds();
}
// 颜色随机


export const randomColor = ()=>{
   return Math.floor(Math.random()*255);
}

// 计算时间,距离当前时间点多久
export const beforeTime = (time)=>{
    const nowTime = moment().valueOf();
    const beforeTime = parseInt(time);
    const interval = nowTime-beforeTime;
    const days = Math.floor(interval/(1000*3600*24));
    const hours = Math.floor(interval/(1000*3600)%24);
    const minutes = Math.floor((interval / (1000 * 60)) % 60);
    if(days>0) {
        return `${days}天前`
    }else if(hours>0) {
        return `${hours}小时前`
    }else if(minutes>5) {
        return `${minutes}分钟前`
    }else {
        return "刚刚"
    }
}
